package com.cll.pmis.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.cll.pmis.common.PageInfo;
import com.cll.pmis.entity.Drug;
import com.cll.pmis.entity.Orders;
import com.cll.pmis.mapper.OrderMapper;
import com.cll.pmis.service.IOrderService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chenliangliang
 * @since 2018-06-18
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Orders> implements IOrderService {

    @Override
    public OrderMapper getMapper() {
        return this.baseMapper;
    }

    @Override
    public PageInfo<Orders> list(Integer userId, Integer pageIndex, Integer pageSize) {
        Page<Orders> page = new Page<>(pageIndex, pageSize);
        List<Orders> orderList = this.baseMapper.queryListByPage(userId, page);
        page.setRecords(orderList);
        return new PageInfo<>(page);
    }

    @Override
    public List<Drug> getOrderDetail(Integer orderId) {
        List<Drug> drugs = this.baseMapper.queryOrderDetail(orderId);
        drugs.forEach(it-> it.setCost(it.getSellPrice().multiply(new BigDecimal(it.getNum()))));
        return drugs;
    }
}
